package com.yhos.platform.oopston.core.manager;

import java.util.Map;

public class TraceParameterThreadLocalManager {

    private InheritableThreadLocal<TraceParameterBean> threadLocal = new InheritableThreadLocal<>();

    private static TraceParameterThreadLocalManager manager = null;

    private TraceParameterThreadLocalManager() {
    }

    public static synchronized TraceParameterThreadLocalManager getInstance() {
        if (manager == null) {
            manager = new TraceParameterThreadLocalManager();
        }
        return manager;
    }

    public void putParams(Map<String, Object> traceParamsMap) {
        TraceParameterBean params = threadLocal.get();
        if (params == null) {
            params = new TraceParameterBean();
        }
        if (traceParamsMap != null) {
            params.setTraceParamsMap(traceParamsMap);
        }
        threadLocal.set(params);
    }

    public TraceParameterBean getParams() {
        return threadLocal.get();
    }

    public void removeParams() {
        threadLocal.set(null);
    }

}
